import ajax from '@util/ajax.ts'
import { Result } from '@src/interfaces/TypeResult.ts'
import { TypePageDTO } from '@src/interfaces/TypePageDTO.ts'
import { TypeBalanceApply } from '@src/interfaces/TypeBalanceApply.ts'
import { TypeUser } from '@src/interfaces/TypeUser.ts'

/**
 * 获取班费申请记录
 */
export const getClassBalanceApplyListApi = (params: {
  page: number
  size: number
}) => {
  return ajax
    .get('balance-apply/page', {
      params,
    })
    .then(({ data }) => {
      return data as Result<TypePageDTO<TypeBalanceApply & { user: TypeUser }>>
    })
}

/**
 * 同意申请
 */
export const agreeBalanceApplyApi = (balanceApply: TypeBalanceApply) => {
  return ajax.put(`balance-apply/agree`, balanceApply).then(({ data }) => {
    return data as Result<null>
  })
}

/**
 * 拒绝申请
 */
export const refuseBalanceApplyApi = (balanceApply: TypeBalanceApply) => {
  return ajax.put(`balance-apply/refuse`, balanceApply).then(({ data }) => {
    return data as Result<null>
  })
}

/**
 * 撤回申请
 */
export const revokeBalanceApplyApi = (balanceApply: TypeBalanceApply) => {
  return ajax.put(`balance-apply/revoke`, balanceApply).then(({ data }) => {
    return data as Result<null>
  })
}

/**
 * 申请班费
 */
export const applyBalanceApi = (balanceApply: TypeBalanceApply) => {
  return ajax.post(`balance-apply`, balanceApply).then(({ data }) => {
    return data as Result<null>
  })
}
